package com.molichuxing.services.business.convertor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.molichuxing.services.business.dto.request.modify.StockCarRejectionBizModifyDto;
import com.molichuxing.services.business.dto.response.EntrepotStorageBizDto;
import com.molichuxing.services.business.dto.response.StockCarBizDto;
import com.molichuxing.services.business.dto.response.StockCarDetailDto;
import com.molichuxing.services.business.dto.response.StockRecordBizDto;
import com.molichuxing.services.infrastructure.dto.request.create.StockRecordCreateDto;
import com.molichuxing.services.infrastructure.dto.response.EntrepotStorageDto;
import com.molichuxing.services.infrastructure.dto.response.StockCarDto;
import com.molichuxing.services.infrastructure.dto.response.StockRecordDto;
import com.molichuxing.services.property.StockCarStockTypeEnum;
import com.molichuxing.services.property.StockRecordStatusEnum;
import com.molichuxing.services.property.StockRecordTypeEnum;

/**
 * 
 * @author liyg 组合服务数据转换类 2019-08-20
 *
 */
public class Convert {

	public static List<EntrepotStorageBizDto> toEntrepotStorageBizDto(List<EntrepotStorageDto> dtoList) {
		List<EntrepotStorageBizDto> bizDtoList = null;
		if (dtoList != null && dtoList.size() > 0) {
			bizDtoList= new ArrayList<>();
			for (EntrepotStorageDto dto : dtoList) {
				bizDtoList.add(toEntrepotStorageBizDto(dto));
			}
		}

		return bizDtoList;
	}

	public static EntrepotStorageBizDto toEntrepotStorageBizDto(EntrepotStorageDto dto) {
		EntrepotStorageBizDto bizDto = null;
		if (dto != null) {
			bizDto = new EntrepotStorageBizDto();
			BeanUtils.copyProperties(dto, bizDto);
		}
		return bizDto;
	}

	public static List<StockRecordBizDto> toStockRecordBizDto(List<StockRecordDto> dtoList) {
		List<StockRecordBizDto> bizDtoList = null;
		if (dtoList != null && dtoList.size() > 0) {
			bizDtoList= new ArrayList<>();
			for (StockRecordDto dto : dtoList) {
				bizDtoList.add(toStockRecordBizDto(dto));
			}
		}

		return bizDtoList;
	}

	public static StockRecordBizDto toStockRecordBizDto(StockCarDto dto) {
		StockRecordBizDto bizDto = null;
		if (dto != null) {
			bizDto = new StockRecordBizDto();
			BeanUtils.copyProperties(dto, bizDto);
			bizDto.setType(StockRecordTypeEnum.PURCHASE_IN_STOCK.getValue());
		}
		return bizDto;
	}
	
	public static StockRecordBizDto toStockRecordBizDto(StockRecordDto dto) {
		StockRecordBizDto bizDto = null;
		if (dto != null) {
			bizDto = new StockRecordBizDto();
			BeanUtils.copyProperties(dto, bizDto);
		}
		return bizDto;
	}
	
	public static List<StockCarBizDto> toStockCarBizDto(List<StockCarDto> dtoList) {
		List<StockCarBizDto> bizDtoList = null;
		if (dtoList != null && dtoList.size() > 0) {
			bizDtoList= new ArrayList<>();
			for (StockCarDto dto : dtoList) {
				bizDtoList.add(toStockCarBizDto(dto));
			}
		}

		return bizDtoList;
	}

	public static StockCarBizDto toStockCarBizDto(StockCarDto dto) {
		StockCarBizDto bizDto = null;
		if (dto != null) {
			bizDto = new StockCarBizDto();
			BeanUtils.copyProperties(dto, bizDto);
		}
		return bizDto;
	}
	
	public static StockCarDetailDto toStockCarDetailDto(StockCarDto dto) {
		StockCarDetailDto bizDto = null;
		if (dto != null) {
			bizDto = new StockCarDetailDto();
			BeanUtils.copyProperties(dto, bizDto);
		}
		return bizDto;
	}
	
	public static List<StockCarDetailDto> toStockCarDetailDto(List<StockCarDto> dtoList) {
		List<StockCarDetailDto> bizDtoList = null;
		if (dtoList != null && dtoList.size() > 0) {
			bizDtoList= new ArrayList<>();
			for (StockCarDto dto : dtoList) {
				bizDtoList.add(toStockCarDetailDto(dto));
			}
		}

		return bizDtoList;
	}
	
	public static StockRecordCreateDto toStockRecordCreateDto(StockCarRejectionBizModifyDto modifyDto,StockCarDto stockCarDto) {
		StockRecordCreateDto stockRecordCreateDto = new StockRecordCreateDto();
		stockRecordCreateDto.setCarId(stockCarDto.getCarId());
		stockRecordCreateDto.setVehicleId(stockCarDto.getVehicleId());
		stockRecordCreateDto.setOutStockId(stockCarDto.getInStockId());
		stockRecordCreateDto.setOutStockType(stockCarDto.getInStockType());
		stockRecordCreateDto.setOutOperationTime(modifyDto.getStorageTime());
		stockRecordCreateDto.setOutAccountAccount(modifyDto.getAccountAccount());
		stockRecordCreateDto.setOutAccountId(modifyDto.getAccountId());
		stockRecordCreateDto.setInStockId(modifyDto.getStockId());
		stockRecordCreateDto.setInStockType(StockCarStockTypeEnum.ENTREPOT_STORAGE.getValue());
		stockRecordCreateDto.setStatus(StockRecordStatusEnum.IN_STOCK.getValue());
		stockRecordCreateDto.setType(StockRecordTypeEnum.REJECTION_IN_STOCK.getValue());
		//入库时间
		stockRecordCreateDto.setOperationTime(modifyDto.getStorageTime());
		stockRecordCreateDto.setPdiUrl(stockCarDto.getPdiUrl());
		stockRecordCreateDto.setAccountId(modifyDto.getAccountId());
		stockRecordCreateDto.setAccountAccount(modifyDto.getAccountAccount());
		return stockRecordCreateDto;
	}
}
